package config

import "github.com/gin-gonic/gin"

// ClientConfig 后台公共配置
var ClientConfig = clientConfig{
	// 管理缓存键
	BackstageManageKey: "backstage:client:manage",
	// 令牌缓存键
	BackstageTokenKey: "backstage:client:token:",
	// 令牌的集合
	BackstageTokenSet: "backstage:client:token:set:",
	// 配置的缓存键
	BackstagePayConfigSet: "backstage:client:pay:flag:",
	// 应用的缓存键
	BackstageAppConfigSet: "backstage:client:app:flag:",
	// 应用的缓存键
	BackstageOrderQueueKey: "Like:backstage:client:order:queue",

	// 免登录验证
	NotLoginUri: []string{
		"user:login",              // 登录接口
		"user:pay:notify:channel", // 支付回调
	},

	// 演示模式白名单
	ShowWhitelistUri: []string{
		"user:login",  // 登录接口
		"user:logout", // 退出登录
	},

	// 请求临时数据
	SuperAdminId:   1,
	ReqAdminIdKey:  "client_id",
	ReqUsernameKey: "username",
	ReqNicknameKey: "nickname",
}

type clientConfig struct {
	BackstageManageKey     string
	BackstageTokenKey      string
	BackstageTokenSet      string
	BackstagePayConfigSet  string
	BackstageAppConfigSet  string
	BackstageOrderQueueKey string
	NotLoginUri            []string
	ShowWhitelistUri       []string
	SuperAdminId           uint
	ReqAdminIdKey          string
	ReqUsernameKey         string
	ReqNicknameKey         string
}

func (cnf clientConfig) GetAdminId(c *gin.Context) uint {
	adminId, ok := c.Get(cnf.ReqAdminIdKey)
	if !ok {
		return 0
	}
	return adminId.(uint)
}

func (cnf clientConfig) GetUsername(c *gin.Context) string {
	username, ok := c.Get(cnf.ReqUsernameKey)
	if !ok {
		return ""
	}
	return username.(string)
}

func (cnf clientConfig) GetNickname(c *gin.Context) string {
	nickname, ok := c.Get(cnf.ReqNicknameKey)
	if !ok {
		return ""
	}
	return nickname.(string)
}
